﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;
using System.IO;
using System.Reflection;
using FinosLibrary;
namespace BattleShipOnline
{
	public partial class LoginPanel : UserControl
	{
        public string State {
            get { return (string)this.GetValue(StateProperty); }
            set { 
                this.SetValue(StateProperty, value);
            }
        }
        public static readonly DependencyProperty StateProperty = DependencyProperty.Register(
          "State", typeof(string), typeof(LoginPanel), new PropertyMetadata("normal", (DependencyObject o,DependencyPropertyChangedEventArgs e) => {
              if(e.NewValue!=null)VisualStateManager.GoToState((Control)o, (string)e.NewValue, true);
          }));

		public LoginPanel()
		{
			// Required to initialize variables
			InitializeComponent();
			if (App.Current.IsRunningOutOfBrowser) {
                button_Copy.Visibility = Visibility.Collapsed;
            }
            this.success.Storyboard.Completed += (object sender, EventArgs e) =>
                MainPage.ChangeContent(new SecondPage());
		}

		
		private void button_Click(object sender, RoutedEventArgs e) {
            ModelLogic.doLogic("ConnectAndLogin");
        }
		private void button_Copy_Click(object sender, RoutedEventArgs e) {
            App.Current.Install();
        }

		 private void UserControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
		 {
             var custom = Custom.GetCustom();
             if (custom != null) {
                 textBox.Text = custom.name;
                 passwordBox.Password = custom.password;
                 checkBox.IsChecked = custom.usePassword;
                 textBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
                 passwordBox.GetBindingExpression(PasswordBox.PasswordProperty).UpdateSource();
                 checkBox.GetBindingExpression(CheckBox.IsCheckedProperty).UpdateSource();
             }
		 }
	}
}